package com.ruoyi.medicine1.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.medicine1.domain.TbMedicine;
import com.ruoyi.medicine1.service.ITbMedicineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品基本信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/medicine1/medic")
public class TbMedicineController extends BaseController
{
    @Autowired
    private ITbMedicineService tbMedicineService;

    /**
     * 查询药品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('medicine1:medic:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMedicine tbMedicine)
    {
        startPage();
        List<TbMedicine> list = tbMedicineService.selectTbMedicineList(tbMedicine);
        return getDataTable(list);
    }

    /**
     * 导出药品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('medicine1:medic:export')")
    @Log(title = "药品基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMedicine tbMedicine)
    {
        List<TbMedicine> list = tbMedicineService.selectTbMedicineList(tbMedicine);
        ExcelUtil<TbMedicine> util = new ExcelUtil<TbMedicine>(TbMedicine.class);
        util.exportExcel(response, list, "药品基本信息数据");
    }

    /**
     * 获取药品基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine1:medic:query')")
    @GetMapping(value = "/{medicineId}")
    public AjaxResult getInfo(@PathVariable("medicineId") Long medicineId)
    {
        return success(tbMedicineService.selectTbMedicineByMedicineId(medicineId));
    }

    /**
     * 新增药品基本信息
     */
    @PreAuthorize("@ss.hasPermi('medicine1:medic:add')")
    @Log(title = "药品基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMedicine tbMedicine)
    {
        return toAjax(tbMedicineService.insertTbMedicine(tbMedicine));
    }

    /**
     * 修改药品基本信息
     */
    @PreAuthorize("@ss.hasPermi('medicine1:medic:edit')")
    @Log(title = "药品基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMedicine tbMedicine)
    {
        return toAjax(tbMedicineService.updateTbMedicine(tbMedicine));
    }

    /**
     * 删除药品基本信息
     */
    @PreAuthorize("@ss.hasPermi('medicine1:medic:remove')")
    @Log(title = "药品基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{medicineIds}")
    public AjaxResult remove(@PathVariable Long[] medicineIds)
    {
        return toAjax(tbMedicineService.deleteTbMedicineByMedicineIds(medicineIds));
    }
}
